/**
 * Copyright 2009-2021 the original author or authors.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package zy.blue7.mybatis.test.xml.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.builder.SqlSourceBuilder;
import zy.blue7.mybatis.test.xml.model.Person;

/**
 * @author blue7
 * @create 2021/5/17 13:50
 */
public interface PersonDao {
    int insert(Person p);

    Person select(Integer id);

    /**
     * @param i
     * @return
     * @see SqlSourceBuilder#parse(java.lang.String, java.lang.Class, java.util.Map)
     * 必须使用   todo #{ }
     */
    @Select("<script>"
            + " SELECT *  FROM  person WHERE  id= #{id}"
            + "</script>"
    )
    Person selectById(@Param("id") Integer i);

    @SelectKey(statement = " select last_insert_id() ", keyProperty = "id", keyColumn = "id", before = false, resultType = int.class)
    @Insert("<script>"
            + "INSERT INTO person (name, age, phone, email, address) VALUES(#{name},#{age},#{phone},#{email},#{address})"
            + "</script>")
    int insertBySelectKey(Person p);
}
